"""
Case Type   : 系统表
Case Name   : 测试系统表stat_xact_all_tables和global_stat_all_tables相关信息
Create At   : 2024.4.1
Owner       : haomeng
Description :
    1.查看object中stat_xzct_all_tables和global_stat_xact_all_tables的相关信息
Expect      :
    1.两个对象的输出信息完全一致
History     :
"""

import os
import unittest
from testcase.utils.Logger import Logger
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH


class SystemTable(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.comsh = CommonSH('PrimaryDbUser')
        self.com = Common()

    def test_system_table(self):
        text = '---step1:查看object中stat_xzct_all_tables和' \
               'global_stat_xact_all_tables的相关信息; expect:两个对象的输出信息完全一致---'
        self.log.info(text)

        sql1 = 'select schemaname,count(schemaname) from ' \
               'dbe_perf.stat_xact_all_tables group by schemaname;'
        self.log.info(sql1)
        sql1_res = self.comsh.execut_db_sql(sql1)
        self.log.info(sql1_res)

        sql2 = 'select schemaname,count(*) from ' \
               'dbe_perf.global_stat_all_tables group by schemaname;'
        self.log.info(sql2)
        sql2_res = self.comsh.execut_db_sql(sql2)
        self.log.info(sql2_res)

        self.assertEqual(sql1_res, sql2_res, '执行失败:' + text)

    def tearDown(self):
        self.log.info('-----无须清理环境-----')
        self.log.info(f'-----{os.path.basename(__file__)} end-----')
